package fairygui.editor.dialogs
{
   import fairygui.GButton;
   import fairygui.GList;
   import fairygui.ListSelectionMode;
   import fairygui.UIPackage;
   import fairygui.editor.Consts;
   import fairygui.editor.EditorWindow;
   import fairygui.editor.WindowBase;
   import fairygui.editor.gui.EUIPackage;
   import fairygui.editor.settings.AtlasSettings;
   import fairygui.editor.settings.PublishSettings;
   import fairygui.event.StateChangeEvent;
   import flash.events.Event;
   
   public class AtlasSettingsDialog extends WindowBase
   {
       
      
      private var _pkg:EUIPackage;
      
      private var _list:GList;
      
      private var _compression:GButton;
      
      public function AtlasSettingsDialog(param1:EditorWindow)
      {
         super();
         _editorWindow = param1;
         this.contentPane = UIPackage.createObject("Builder","AtlasSettingsDialog").asCom;
         this.centerOn(_editorWindow.groot,true);
         this.modal = true;
         this._list = contentPane.getChild("list").asList;
         this._list.selectionMode = ListSelectionMode.None;
         this._compression = contentPane.getChild("header").asCom.getChild("compression").asButton;
         this._compression.addEventListener(StateChangeEvent.CHANGED,this.__compressionChanged);
         contentPane.getChild("ok").addClickListener(this.__save);
         contentPane.getChild("cancel").addClickListener(closeEventHandler);
      }
      
      public function open(param1:EUIPackage) : void
      {
         var _loc5_:Boolean = false;
         var _loc7_:AtlasSettings = null;
         var _loc8_:GButton = null;
         this._pkg = param1;
         var _loc2_:PublishSettings = param1.publishSettings;
         var _loc3_:AtlasSettings = _loc2_.atlasList[0];
         contentPane.getChild("maxAtlasSize").asComboBox.value = "" + _loc3_.maxWidth;
         contentPane.getChild("npot").asButton.selected = !_loc3_.pot;
         contentPane.getChild("square").asButton.selected = _loc3_.square;
         contentPane.getChild("rotation").asButton.selected = _loc3_.rotation;
         contentPane.getChild("extractAlpha").asButton.selected = _loc3_.extractAlpha;
         contentPane.getChild("multiPage").asButton.selected = _loc3_.multiPage;
         var _loc4_:Vector.<AtlasSettings> = _loc2_.atlasList;
         this._list.removeChildrenToPool();
         var _loc6_:int = 0;
         while(_loc6_ < _loc4_.length)
         {
            _loc7_ = _loc4_[_loc6_];
            _loc8_ = this._list.addItemFromPool().asButton;
            _loc8_.getChild("index").text = "" + _loc6_;
            if(_loc6_ == 0 && !_loc7_.name)
            {
               _loc8_.getChild("name").text = Consts.g.text80;
            }
            else
            {
               _loc8_.getChild("name").text = _loc7_.name;
            }
            _loc8_.getChild("compression").asButton.selected = _loc7_.compression;
            if(!_loc7_.compression)
            {
               _loc5_ = true;
            }
            _loc6_++;
         }
         this._compression.selected = !_loc5_;
         show();
      }
      
      private function __save(param1:Event) : void
      {
         var _loc11_:AtlasSettings = null;
         var _loc12_:GButton = null;
         var _loc2_:PublishSettings = this._pkg.publishSettings;
         var _loc3_:int = parseInt(contentPane.getChild("maxAtlasSize").asComboBox.value);
         var _loc4_:* = !contentPane.getChild("npot").asButton.selected;
         var _loc5_:Boolean = contentPane.getChild("square").asButton.selected;
         var _loc6_:Boolean = contentPane.getChild("rotation").asButton.selected;
         var _loc7_:Boolean = contentPane.getChild("extractAlpha").asButton.selected;
         var _loc8_:Boolean = contentPane.getChild("multiPage").asButton.selected;
         var _loc9_:Vector.<AtlasSettings> = _loc2_.atlasList;
         var _loc10_:int = 0;
         while(_loc10_ < _loc9_.length)
         {
            _loc11_ = _loc9_[_loc10_];
            _loc12_ = this._list.getChildAt(_loc10_).asButton;
            _loc11_.name = _loc12_.getChild("name").text;
            _loc11_.maxWidth = _loc11_.maxHeight = _loc3_;
            _loc11_.pot = _loc4_;
            _loc11_.square = _loc5_;
            _loc11_.rotation = _loc6_;
            _loc11_.extractAlpha = _loc7_;
            _loc11_.compression = _loc12_.getChild("compression").asButton.selected;
            _loc11_.multiPage = _loc8_;
            _loc10_++;
         }
         this._pkg.save();
         this.hide();
      }
      
      private function __compressionChanged(param1:Event) : void
      {
         var _loc2_:Boolean = GButton(param1.currentTarget).selected;
         var _loc3_:PublishSettings = this._pkg.publishSettings;
         var _loc4_:Vector.<AtlasSettings> = _loc3_.atlasList;
         var _loc5_:int = 0;
         while(_loc5_ < _loc4_.length)
         {
            this._list.getChildAt(_loc5_).asCom.getChild("compression").asButton.selected = _loc2_;
            _loc5_++;
         }
      }
   }
}
